<template>
  <div class="user">
    <el-card class="box-card" v-if="status === 'index'">
      <el-row>
        <el-input
          v-model="searchParams.name"
          placeholder="请输入赏品名称"
          clearable
          style="width:200px"
          size="mini"
        ></el-input>
        <el-date-picker
          v-model="searchParams.startTime"
          type="datetime"
          placeholder="选择开始时间"
          :picker-options="pickerOptions"
          size="mini"
        ></el-date-picker>
        <el-date-picker
          v-model="searchParams.endTime"
          type="datetime"
          placeholder="选择结束时间"
          :picker-options="pickerOptions"
          size="mini"
        ></el-date-picker>
        <el-button
          type="primary"
          size="mini"
          @click="getData"
          v-if="has('fusionPrizes/index')"
        >搜索
        </el-button
        >
        <el-button
          type="info"
          size="mini"
          @click="reset"
          v-if="has('fusionPrizes/index')"
        >重置
        </el-button
        >
        <el-button
          type="primary"
          @click="prize()"
          size="mini"
          v-if="has('fusionPrizes/store')"
        >添加
        </el-button
        >
      </el-row>
      <el-table
        :data="data.data"
        v-loading="table_loading"
        style="width: 100%;margin:10px auto"
        size="mini"
        :header-cell-style="{ background: '#f3f8fe', color: '#333' }"
      >
        <el-table-column
          fixed
          prop="id"
          label="赏品信息"
          align="center"
          width="160px"
        >
          <template slot-scope="scope">
            <div style="display: flex;align-items: center;">
              <el-image
                :src="scope.row.image"
                :style="{
                  width: '50px',
                  height: '50px',
                  borderRadius: '5px',
                  marginRight: '10px'
                }"
                :preview-src-list="[scope.row.image]"
                fit="contain"
              ></el-image>
              <div>
                <div>{{ scope.row.name }}</div>
                <div>ID:{{ scope.row.id }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="level_name" label="等级" align="center">
          <template slot-scope="scope">
            <span
              :style="{
                backgroundColor: scope.row.level_color,
                color: '#fff',
                padding: '10px',
                height: '20px',
                lineHeight: '20px',
                textAlign: 'center',
                width: '100px',
                borderRadius: '10px'
              }"
            >
              {{ scope.row.level_name }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          prop="price"
          label="单抽价"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="recovery_price"
          label="兑换价"
          align="center"
          v-slot:default="{ row }"
        >
          <el-input
            @blur="updateRecoveryPrice(row)"
            @click.native="row.focus = true"
            v-model="row.recovery_price"
          ></el-input>
        </el-table-column>
        <el-table-column
          prop="num"
          label="数量"
          align="center"
          v-slot:default="{ row }"
        >
          <el-input
            @blur="updateNum(row)"
            @click.native="row.focus = true"
            v-model="row.num"
          ></el-input>
        </el-table-column>
        <el-table-column prop="status" label="状态" align="center">
          <template slot-scope="scope">
            <el-switch
              @change="changeStatus(scope.row)"
              v-model="scope.row.status"
              active-color="#13ce66"
              inactive-color="#ff4949"
              :active-value="activeValue"
              :inactive-value="inactiveValue"
            >
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column
          prop="created_at"
          label="时间"
          align="center"
        ></el-table-column>

        <el-table-column fixed="right" label="操作" align="center" width="300">
          <template slot-scope="scope">
            <el-button
              type="danger"
              size="mini"
              @click="del(scope.row.id, scope.$index)"
              v-if="has('fusionPrizes/destroy')"
            >删除
            </el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        style="text-align:center;margin:20px 0;"
        :current-page="searchParams.page"
        :page-sizes="pageSizes"
        layout="total,prev, pager, next,sizes"
        :total="data.total"
        @size-change="changeSize"
        @current-change="changePage"
      ></el-pagination>
    </el-card>

    <el-card v-if="status === 'add'">
      <div slot="header">
        <el-page-header @back="back()" content="添加盲盒"></el-page-header>
      </div>
      <el-form
        ref="form"
        :rules="rules"
        :model="editParams"
        label-width="120px"
      >
        <el-form-item label="盲盒名称" prop="name">
          <el-input v-model="editParams.name" style="width: 300px;"></el-input>
        </el-form-item>

        <el-form-item label="盲盒类型" prop="cat_id">
          <el-select
            v-model="editParams.cat_id"
            placeholder="请选择盲盒类型"
            clearable
          >
            <el-option
              v-for="item in catData"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="单抽价格" prop="price">
          <el-input v-model="editParams.price" style="width: 300px;"></el-input>
        </el-form-item>
        <el-form-item label="临界值" prop="income_value">
          <el-input
            v-model="editParams.income_value"
            style="width: 300px;"
          ></el-input>
        </el-form-item>

        <el-form-item label="临界商品id" prop="income_id">
          <el-input
            v-model="editParams.income_id"
            style="width: 300px;"
          ></el-input>
        </el-form-item>

        <el-form-item label="图片" prop="image">
          <el-button size="mini" type="primary" @click="openImage(2, false, {})"
          >选择商品库
          </el-button
          >
          <div>
            <el-image
              v-if="editParams.image"
              :src="editParams.image"
              :preview-src-list="[editParams.image]"
              style="height: 200px"
              fit="contain"
            >
            </el-image>
          </div>
        </el-form-item>

        <el-form-item label="概率" prop="probability">
          <div v-for="(item, index) in editParams.probability" :key="index">
            <div>
              <el-input v-model="item.value" style="width: 300px;">
                <template slot="prepend">{{ item.name }} :</template>
                <template slot="append">%</template>
              </el-input>
            </div>
          </div>
        </el-form-item>

        <el-form-item label="排序" prop="sort">
          <el-input v-model="editParams.sort" style="width: 300px;"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="submit('form', 1)"
            v-if="has('blindBox/store')"
          >保 存
          </el-button
          >
          <el-button type="info" @click="back()" v-if="has('blindBox/store')"
          >取 消
          </el-button
          >
        </el-form-item>
      </el-form>
    </el-card>

    <el-card v-if="status === 'edit'">
      <div slot="header">
        <el-page-header @back="back()" content="编辑盲盒"></el-page-header>
      </div>
      <el-form
        ref="form"
        :rules="rules"
        :model="editParams"
        label-width="120px"
      >
        <el-form-item label="盲盒名称" prop="name">
          <el-input v-model="editParams.name" style="width: 300px;"></el-input>
        </el-form-item>
        <el-form-item label="盲盒类型" prop="cat_id">
          <el-select
            v-model="editParams.cat_id"
            placeholder="请选择盲盒类型"
            clearable
          >
            <el-option
              v-for="item in catData"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="单抽价格" prop="price">
          <el-input v-model="editParams.price" style="width: 300px;"></el-input>
        </el-form-item>
        <el-form-item label="临界值" prop="income_value">
          <el-input
            v-model="editParams.income_value"
            style="width: 300px;"
          ></el-input>
        </el-form-item>
        <el-form-item label="临界商品id" prop="income_id">
          <el-input
            v-model="editParams.income_id"
            style="width: 300px;"
          ></el-input>
        </el-form-item>
        <el-form-item label="图片" prop="image">
          <el-button size="mini" type="primary" @click="openImage(2, false, {})"
          >选择商品库
          </el-button
          >
          <div>
            <el-image
              v-if="editParams.image"
              :src="editParams.image"
              :preview-src-list="[editParams.image]"
              style="height: 200px"
              fit="contain"
            >
            </el-image>
          </div>
        </el-form-item>

        <el-form-item label="概率" prop="probability">
          <div v-for="(item, index) in editParams.probability" :key="index">
            <div>
              <el-input v-model="item.value" style="width: 300px;">
                <template slot="prepend" v-if="item.level_id == 1"
                >尊贵 :
                </template
                >
                <template slot="prepend" v-if="item.level_id == 2"
                >稀有 :
                </template
                >
                <template slot="prepend" v-if="item.level_id == 3"
                >史诗 :
                </template
                >
                <template slot="prepend" v-if="item.level_id == 4"
                >传说 :
                </template
                >
                <template slot="append">%</template>
              </el-input>
            </div>
          </div>
        </el-form-item>

        <el-form-item label="排序" prop="sort">
          <el-input v-model="editParams.sort" style="width: 300px;"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="submit('form', 2)"
            v-if="has('blindBox/store')"
          >保 存
          </el-button
          >
          <el-button type="info" @click="back()" v-if="has('blindBox/store')"
          >取 消
          </el-button
          >
        </el-form-item>
      </el-form>
    </el-card>

    <el-card v-if="status === 'prize'">
      <div slot="header">
        <el-page-header @back="back()" content="赏品列表"></el-page-header>
      </div>
      <el-row>
        <el-input
          v-model="prizeSearchParams.name"
          placeholder="请输入赏品名称"
          clearable
          style="width:200px"
          size="mini"
        ></el-input>
        <el-select
          v-model="prizeSearchParams.levelId"
          style="width:200px"
          clearable
          size="mini"
          placeholder="请选择赏品等级"
        >
          <el-option
            v-for="item in levelData"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option
          >
        </el-select>

        <el-button
          type="primary"
          size="mini"
          @click="getPrize"
          v-if="has('blindBoxPrizes/index')"
        >搜索
        </el-button
        >
        <el-button
          type="primary"
          @click="prize()"
          size="mini"
          v-if="has('blindBoxPrizes/store')"
        >添加
        </el-button
        >
      </el-row>
      <el-table
        :data="prizeData.data"
        v-loading="prizeTableLoading"
        style="width: 100%;margin:10px auto"
        size="mini"
        :header-cell-style="{ background: '#f3f8fe', color: '#333' }"
      >        <el-table-column
        fixed
        prop="id"
        label="赏品信息"
        align="center"
        width="250px"
      >
        <template slot-scope="scope">
          <div style="display: flex;align-items: center;">
            <img
              :src="scope.row.image"
              :style="{
                  width: '50px',
                  height: '50px',
                  borderRadius: '5px',
                  marginRight: '10px'
                }"
              @click="bigImage(scope.row.image)"
            />
            <div>
              <div>赏品ID：{{ scope.row.id }}</div>
              <div>{{ scope.row.name }}</div>
            </div>
          </div>
        </template>
      </el-table-column>
        <el-table-column prop="level_name" label="等级" align="center">
          <template slot-scope="scope">
            <span
              :style="{
                backgroundColor: scope.row.level_color,
                color: '#fff',
                padding: '10px',
                height: '20px',
                lineHeight: '20px',
                textAlign: 'center',
                width: '100px',
                borderRadius: '10px'
              }"
            >
              {{ scope.row.level_name }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          prop="price"
          label="价格"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="recovery_price"
          label="兑换价"
          align="center"
          v-slot:default="{ row }"
        >
          <el-input
            @blur="updatePrice(row)"
            @click.native="row.focus = true"
            v-model="row.recovery_price"
          ></el-input>
        </el-table-column>

        <el-table-column
          prop="probability"
          label="概率"
          align="center"
          v-slot:default="{ row }"
        >
          <el-input
            @blur="updateProbability(row)"
            @click.native="row.focus = true"
            v-model="row.probability"
          ></el-input>
        </el-table-column>

        <el-table-column prop="level_name" label="出奖盈亏值" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.level_id != 1">
              {{
                scope.row.blind_box.price * (100 / scope.row.probability) -
                scope.row.recovery_price
              }}
            </span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="created_at"
          label="时间"
          align="center"
        ></el-table-column>
        <el-table-column fixed="right" label="操作" align="center" width="200">
          <template slot-scope="scope">
            <!-- <el-button
              type="primary"
              size="mini"
              @click="editPrize(scope.row.id)"
              v-if="has('blindBox/show')"
              >编辑</el-button
            > -->
            <el-button @click="giveUser(scope.row)" type="primary" size="mini"
            >赠送
            </el-button>
            <el-button
              type="danger"
              size="mini"
              @click="delPrize(scope.row.id, scope.$index)"
              v-if="has('blindBox/destroy')"
            >删除
            </el-button
            >
          </template>
        </el-table-column>

      </el-table>
      <el-pagination
        background
        style="text-align:center;margin:20px 0;"
        :current-page="prizeSearchParams.page"
        :page-sizes="pageSizes"
        layout="total,prev, pager, next,sizes"
        :total="prizeData.total"
        @size-change="changePrizeSize"
        @current-change="changePrizePage"
      ></el-pagination>
    </el-card>

    <el-dialog title="已选择用户"
               :visible.sync="giveShow"
               :close-on-click-modal="false">
      <el-button @click="addGiveUser" type="primary">添加用户</el-button>
      <el-table
        :data="selectUsers"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column label="ID" width="120" align="center">
          <template v-slot:default="{row}">{{ row.id }}</template>
        </el-table-column>
        <el-table-column
          prop="avatar"
          label="用户头像"
          align="center"
        >
          <template v-slot:default="{row}">
            <div style="display: flex;align-items: center; justify-content: center;">
              <el-image
                :src="row.avatar"
                :style="{
                  width: '50px',
                  height: '50px',
                  borderRadius: '5px',
                  marginRight: '10px'
                }"
                :preview-src-list="[row.avatar]"
                fit="contain"
              ></el-image>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="昵称">
          <template v-slot:default="{row}">{{ row.nickname }}</template>
        </el-table-column>
        <el-table-column label="手机号码">
          <template v-slot:default="{row}">{{ row.mobile }}</template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="giveSubmit">赠送</el-button>
      </div>
    </el-dialog>

    <el-dialog title="选择赠送用户"
               :visible.sync="giveChoose"
               :close-on-click-modal="false">
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="用户ID">
          <el-input
            v-model="giveParams.id"
            placeholder="请输入用户id"
          ></el-input>
        </el-form-item>
        <el-form-item label="手机号码">
          <el-input
            v-model="giveParams.mobile"
            placeholder="请输入手机号"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="searchUser">搜索</el-button>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="chooseDone">确定</el-button>
      </div>

      <el-table
        :data="givePrizes.data"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          width="55">
        </el-table-column>
        <el-table-column label="ID" width="120" align="center">
          <template v-slot:default="{row}">{{ row.id }}</template>
        </el-table-column>
        <el-table-column
          prop="avatar"
          label="用户头像"
          align="center"
        >
          <template v-slot:default="{row}">
            <div style="display: flex;align-items: center; justify-content: center;">
              <el-image
                :src="row.avatar"
                :style="{
                  width: '50px',
                  height: '50px',
                  borderRadius: '5px',
                  marginRight: '10px'
                }"
                :preview-src-list="[row.avatar]"
                fit="contain"
              ></el-image>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="昵称">
          <template v-slot:default="{row}">{{ row.nickname }}</template>
        </el-table-column>
        <el-table-column label="手机号码">
          <template v-slot:default="{row}">{{ row.mobile }}</template>
        </el-table-column>
      </el-table>

      <el-pagination
        background
        style="text-align:center;margin:20px 0;"
        :current-page="givePrizes.current_page"
        :page-sizes="[10,20,30,50,100]"
        layout="total,prev, pager, next,sizes"
        :total="givePrizes.total"
        @size-change="usersChangeSize"
        @current-change="usersChangePage"
      ></el-pagination>

    </el-dialog>

    <el-card v-show="status === 'log'">
      <div slot="header">
        <el-page-header
          @back="back()"
          :content="'抽奖记录:' + logTitle + ':' + logSearchParams.blind_box_id"
        ></el-page-header>
      </div>
      <el-row>
        <el-input
          v-model="logSearchParams.userId"
          placeholder="请输入用户id"
          clearable
          style="width:200px"
          size="mini"
        ></el-input>
        <el-select
          v-model="logSearchParams.levelId"
          style="width:200px"
          clearable
          size="mini"
          placeholder="请选择赏品等级"
        >
          <el-option
            v-for="item in levelData"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option
          >
        </el-select>
        <el-date-picker
          v-model="logSearchParams.startTime"
          type="datetime"
          placeholder="选择开始时间"
          size="mini"
        ></el-date-picker>
        <el-date-picker
          v-model="logSearchParams.endTime"
          type="datetime"
          placeholder="选择结束时间"
          size="mini"
        ></el-date-picker>
        <el-button
          type="primary"
          size="mini"
          @click="getLog"
          v-if="has('blindBoxOrderPrizeLogs/index')"
        >搜索
        </el-button
        >
      </el-row>
      <el-table
        :data="logData.data"
        v-loading="logTableLoading"
        style="width: 100%;margin:10px auto"
        size="mini"
        :header-cell-style="{ background: '#f3f8fe', color: '#333' }"
      >
        <el-table-column type="expand">
          <template slot-scope="props" v-if="props.row.draw_log.length">
            <div v-if="props.row.draw_log">
              <div>
                原始概率：{{
                  JSON.parse(props.row.draw_pro.pro).map(item => {
                    return item / props.row.draw_pro.rate + "%";
                  })
                }}
              </div>
              <div>x 倍数：{{ props.row.draw_pro.rate }}</div>
              <div>计算数组：{{ props.row.draw_pro.pro }}</div>
              <el-table
                :data="props.row.draw_log"
                style="width: 100%;margin:10px auto"
                size="mini"
                :header-cell-style="{ background: '#f3f8fe', color: '#333' }"
              >
                <el-table-column prop="total" label="赏品信息" align="center">
                  <template slot-scope="scope">
                    <span>{{
                        JSON.parse(props.row.draw_pro.prize_id)[scope.$index]
                          .goods_name
                      }}</span>
                  </template>
                </el-table-column>
                <el-table-column prop="total" label="原始概率" align="center">
                  <template slot-scope="scope">
                    {{
                      JSON.parse(props.row.draw_pro.pro)[scope.$index] /
                      props.row.draw_pro.rate +
                      "%"
                    }}
                  </template>
                </el-table-column
                >
                <el-table-column prop="total" label="随机数范围" align="center">
                  <template slot-scope="scope">
                    <span>1~{{ scope.row.total }}</span>
                  </template>
                </el-table-column
                >

                <el-table-column
                  prop="value"
                  label="产生随机数"
                  align="center"
                ></el-table-column>

                <el-table-column prop="total" label="命中范围" align="center">
                  <template slot-scope="scope">
                    <span>1~{{ scope.row.current_value }}</span>
                  </template>
                </el-table-column
                >
                <el-table-column prop="total" label="命中概率" align="center">
                  <template slot-scope="scope">
                    <span>{{ scope.row.current_value / scope.row.total }}</span>
                  </template>
                </el-table-column
                >
                <el-table-column prop="total" label="是否命中" align="center">
                  <template slot-scope="scope">
                    <span v-if="scope.row.hit == 1" style="color:green"
                    >是</span
                    >
                    <span v-if="scope.row.hit == 0" style="color:red">否</span>
                  </template>
                </el-table-column
                >
                <el-table-column
                  prop="times"
                  label="次数"
                  align="center"
                ></el-table-column>
              </el-table>
            </div>
          </template>
        </el-table-column>

        <el-table-column
          label="用户信息"
          align="center"
          prop="user_id"
          width="150px"
        >
          <template slot-scope="scope">
            <div style="display: flex;">
              <el-image
                :src="scope.row.avatar"
                :preview-src-list="[scope.row.avatar]"
                fit="contain"
                :style="{
                  width: '50px',
                  height: '50px',
                  borderRadius: '5px',
                  marginRight: '10px',
                  alignItems: 'center'
                }"
              ></el-image>
              <div
                style="display: flex;flex-direction: column;justify-content: space-between;"
              >
                <span>{{ scope.row.nickname }}</span>
                <span>ID:{{ scope.row.user_id }}</span>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="赏品信息" align="center" width="300px">
          <template slot-scope="scope">
            <div style="display: flex;align-items: center;">
              <el-image
                :src="scope.row.blind_box_prize_image"
                :preview-src-list="[scope.row.blind_box_prize_image]"
                :style="{
                  width: '50px',
                  height: '50px',
                  marginRight: '10px'
                }"
              ></el-image>
              <div>
                <div>{{ scope.row.blind_box_prize_name }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="level_name" label="等级" align="center">
          <template slot-scope="scope">
            <span
              :style="{
                backgroundColor: scope.row.level_color,
                color: '#fff',
                padding: '10px',
                height: '20px',
                lineHeight: '20px',
                textAlign: 'center',
                width: '100px',
                borderRadius: '10px'
              }"
            >
              {{ scope.row.level_name }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          prop="times"
          label="序号"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="num"
          label="数量"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="price"
          label="价值"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="recovery_price"
          label="兑换价"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="created_at"
          label="创建时间"
          align="center"
        ></el-table-column>
        <el-table-column fixed="right" label="操作" align="center" width="100">
          <template slot-scope="scope">
            <el-button
              type="danger"
              size="mini"
              @click="delLog(scope.row.id)"
              v-if="has('blindBoxOrderPrizeLogs/destroy')"
            >删除
            </el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        style="text-align:center;margin:20px 0;"
        :current-page="logSearchParams.page"
        :page-sizes="pageSizes"
        layout="total,prev, pager, next,sizes"
        :total="logData.total"
        @size-change="changeLogSize"
        @current-change="changeLogPage"
      ></el-pagination>
    </el-card>

    <el-dialog
      title="确定赏品"
      :visible.sync="prizeStatus"
      width="80%"
      :close-on-click-modal="false"
    >
      <el-row>
        <el-button
          type="primary"
          @click="selectPrize()"
          size="mini"
          v-if="has('fusionPrizes/store')"
        >选择赏品
        </el-button
        >
      </el-row>
      <el-table :data="submitPrizeData" v-if="submitPrizeData.length > 0">
        <el-table-column
          fixed
          prop="id"
          label="赏品信息"
          align="center"
          width="160px"
        >
          <template slot-scope="scope">
            <div style="display: flex;align-items: center;">
              <img
                :src="scope.row.image"
                :style="{
                  width: '50px',
                  height: '50px',
                  borderRadius: '5px',
                  marginRight: '10px'
                }"
                @click="bigImage(scope.row.image)"
              />
              <div>
                <div>{{ scope.row.name }}</div>
                <div>{{ scope.row.id }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="price" label="等级" align="center">
          <template slot-scope="scope">
            <span
              :style="{
                backgroundColor: scope.row.level.color,
                color: '#fff',
                padding: '10px',
                height: '20px',
                lineHeight: '20px',
                textAlign: 'center',
                width: '100px',
                borderRadius: '10px'
              }"
            >
              {{ scope.row.level.name }}
            </span>
          </template>
        </el-table-column>

        <el-table-column
          prop="price"
          label="价格"
          align="center"
        ></el-table-column>
        <el-table-column prop="recovery_price" label="兑换价" align="center">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.recovery_price"
              placeholder="请输入兑换价"
            ></el-input>
          </template>
        </el-table-column>

        <el-table-column prop="num" label="数量" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.num" placeholder="请输入数量">
            </el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="created_at"
          label="时间"
          align="center"
        ></el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addPrizeSubmit">保 存</el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="选择赏品"
      :visible.sync="addPrizeStatus"
      :close-on-click-modal="false"
    >
      <el-row>
        <el-select
          v-model="selectPrizeParams.levelId"
          style="width:200px"
          clearable
          size="mini"
          placeholder="请选择赏品等级"
        >
          <el-option
            v-for="item in levelData"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option
          >
        </el-select>
        <el-button type="primary" @click="getSelectPrize()" size="mini"
        >搜索
        </el-button
        >
      </el-row>
      <el-table
        :data="selectPrizeData.data"
        @selection-change="changePrize"
        v-loading="addPrizeLoading"
      >
        <el-table-column type="selection" width="55"></el-table-column>

        <el-table-column
          fixed
          prop="id"
          label="赏品信息"
          align="center"
          width="160px"
        >
          <template slot-scope="scope">
            <div style="display: flex;align-items: center;">
              <img
                :src="scope.row.image"
                :style="{
                  width: '50px',
                  height: '50px',
                  borderRadius: '5px',
                  marginRight: '10px'
                }"
                @click="bigImage(scope.row.image)"
              />
              <div>
                <div>{{ scope.row.name }}</div>
                <div>{{ scope.row.id }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="price" label="等级" align="center">
          <template slot-scope="scope">
            <span
              :style="{
                backgroundColor: scope.row.level.color,
                color: '#fff',
                padding: '10px',
                height: '20px',
                lineHeight: '20px',
                textAlign: 'center',
                width: '100px',
                borderRadius: '10px'
              }"
            >
              {{ scope.row.level.name }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          prop="price"
          label="价格"
          align="center"
        ></el-table-column>

        <el-table-column
          prop="created_at"
          label="时间"
          align="center"
        ></el-table-column>
      </el-table>

      <el-pagination
        background
        style="text-align:center;margin:20px 0;"
        :current-page="selectPrizeParams.page"
        :page-sizes="pageSizes"
        layout="total,prev, pager, next,sizes"
        :total="selectPrizeData.total"
        @size-change="changeSelectPrizeSize"
        @current-change="changeSelectPrizePage"
      ></el-pagination>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="selectPrizeSubmit">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="编辑赏品" :visible.sync="editPrizeStatus">
      <el-form :model="editPrizeParams">
        <el-form-item label="赏品信息" label-width="100px">
          <div style="display: flex;align-items: center;">
            <img
              :src="editPrizeParams.goods.image"
              :style="{
                width: '50px',
                height: '50px',
                borderRadius: '5px',
                marginRight: '10px'
              }"
              @click="bigImage(editPrizeParams.goods.image)"
            />
            <div>
              <div>{{ editPrizeParams.goods.name }}</div>
              <div>赏品ID：{{ editPrizeParams.id }}</div>
            </div>
          </div>
        </el-form-item>

        <el-form-item label="等级" label-width="100px">
          <el-select
            v-model="editPrizeParams.level_id"
            disabled
            style="width:200px"
          >
            <el-option
              v-for="item in levelData"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="价格" label-width="100px">
          <el-input
            v-model="editPrizeParams.price"
            autocomplete="off"
            style="width:200px"
            disabled
          ></el-input>
        </el-form-item>
        <el-form-item label="兑换价" label-width="100px">
          <el-input
            v-model="editPrizeParams.recovery_price"
            autocomplete="off"
            style="width:200px"
          ></el-input>
        </el-form-item>
        <el-form-item label="概率" label-width="100px">
          <el-input
            v-model="editPrizeParams.probability"
            autocomplete="off"
            style="width:200px"
          >
            <template slot="append">%</template>
          </el-input>
        </el-form-item>
        <!-- <el-form-item label="概率B" label-width="100px">
          <el-input
            v-model="editPrizeParams.b_probability"
            autocomplete="off"
            style="width:200px"
          ></el-input>
        </el-form-item>
        <el-form-item label="主播概率" label-width="100px">
          <el-input
            v-model="editPrizeParams.anchor_probability"
            autocomplete="off"
            style="width:200px"
          ></el-input>
        </el-form-item>
        <el-form-item label="特殊概率" label-width="100px">
          <el-input
            v-model="editPrizeParams.custom_probability"
            autocomplete="off"
            style="width:200px"
          ></el-input>
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="editPrizeSubmit">保存</el-button>
      </div>
    </el-dialog>

    <SimpleImageUpload
      :cardStatus="cardStatus"
      :imageFormatArr="imageFormatArr"
      :imageData="imageData"
      :imageLoading="imageLoading"
      :uploadImageAction="uploadImageUrl"
      :multiple="multiple"
      @uploadImageSuccess="uploadFileSuccess"
      @uploadImageBefore="uploadImageBefore"
      @changeImageSize="changeImageSize"
      @changeImagePage="changeImagePage"
      @changeImageFormat="changeImageFormat"
      @choiceImageConfirm="choiceImageConfirm"
      @closeImage="closeImage"
      @getImages="getImages"
    ></SimpleImageUpload>
  </div>
</template>

<script>
import api from "../../api/api.js";
import SimpleImageUpload from "@/components/SimpleImageUpload/index.vue";

export default {
  name: "user",
  components: {
    SimpleImageUpload
  },
  data() {
    return {
      status: "index", // 页面控制
      data: {data: []}, // 表格诗句
      levelData: [],
      table_loading: true, // 表格加载中
      loading: false, //全局加载中
      pageSizes: [10, 20, 50, 100, 200, 500, 800, 1000, 2000], // 每页条数默认10
      pickerOptions: {
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            }
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            }
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            }
          }
        ]
      },
      searchParams: {
        // 搜索参数
        page: 1,
        limit: 10,
        name: ""
      },
      editParams: {
        name: "",
        cat_id: "",
        image: "",
        sort: "",
        price: "",
        three_price: "",
        five_price: "",
        probability: [
          {name: "尊贵", level_id: 1},
          {name: "稀有", level_id: 2},
          {name: "史诗", level_id: 3},
          {name: "传说", level_id: 4}
        ]
      },
      catData: [
        {id: 1, name: "热门盲盒"},
        {id: 2, name: "快乐加倍"}
      ],

      rules: {
        // 验证规则
        name: [{required: true, message: "请输入盲盒名称", trigger: "blur"}],
        cat_id: [
          {required: true, message: "请输入盲盒分类", trigger: "blur"}
        ],
        price: [
          {required: true, message: "请输入单抽价格", trigger: "change"}
        ],
        three_price: [
          {required: true, message: "请输入三连抽价格", trigger: "blur"}
        ],
        five_price: [
          {required: true, message: "请输入五连抽价格", trigger: "blur"}
        ],
        sort: [{required: true, message: "请输入排序", trigger: "blur"}],
        income_value: [
          {required: true, message: "请输入临界值", trigger: "blur"}
        ],
        income_id: [
          {required: true, message: "请输入临界商品", trigger: "blur"}
        ],
        sort: [{required: true, message: "请输入排序", trigger: "blur"}],
        probability: [
          {required: true, message: "请输入概率", trigger: "blur"}
        ],
        image: [{required: true, message: "请上传图片", trigger: "blur"}]
      },

      activeValue: 1,
      inactiveValue: 0,

      cardStatus: false,
      imageFormatArr: [
        {id: "", title: "全部"},
        {id: 1, title: "商品图片"},
        {id: 2, title: "商品详情图"},
        {id: 3, title: "banner"},
        {id: 4, title: "活动"},
        {id: 5, title: "盲盒"}
      ],
      imageParams: {
        format: "",
        page: 1
      },
      imageData: {},
      imageLoading: false,
      uploadImageUrl: "/admin/common/upload?format=5",
      multiple: false,
      scene: 1, // 打开组件场景
      extra: {},

      prizeData: {data: []},
      prizeSearchParams: {
        blindBoxId: "",
        name: "",
        levelId: "",
        page: 1,
        limit: 10
      },
      prizeTableLoading: true, // 赏品表格加载中
      prizeStatus: false,
      submitPrizeData: [],
      selectPrizeData: {data: []},
      addPrizeStatus: false,
      addPrizeData: [],
      editPrizeStatus: false,
      editPrizeParams: {
        id: "",
        goods: {}
      },
      addPrizeLoading: true,
      selectPrizeParams: {levelId: "", page: 1, limit: 20},
      logData: {data: []},
      logSearchParams: {
        // 搜索参数
        userId: "",
        levelId: "",
        page: 1,
        limit: 10,
        blind_box_id: "",
        startTime: "",
        endTime: ""
      },
      logTableLoading: true,
      logTitle: "",
      giveParams: {
        userId: "",
        phone: "",
      },
      givePrizes: {
        data: []
      },
      selectUsers: [],
      currentUsers: [],
      blind_box_id: [],
      giveShow: false,
      giveChoose: false,
      givePrizeId: 0,
      giveGoodsId: 0,
    };
  },
  created() {
    this.getData();
    this.getLevel();
  },

  methods: {
    searchUser() {
      this.giveParams.page = 1
      this.queryUser()
    },
    chooseDone() {
      this.giveChoose = false
      this.selectUsers.push(...this.currentUsers)
      this.currentUsers = []
    },
    addGiveUser() {
      this.giveChoose = true
      this.givePrizes = []
      this.queryUser()
    },
    giveSubmit() {
      const ids = this.selectUsers.map(v => v.id)
      console.log(ids, this.givePrizeId)
      api.users
        .giveUserPrize({ids, blind_box_id: this.givePrizeId,prize_id:this.giveGoodsId})
        .then(res => {
          if (res.data.code == 200) {
            this.$message({
              message: '赠送成功',
              type: 'success'
            });
            this.giveShow = false;
          }
        })
        .catch(error => {
          console.log(error);
        });
      this.selectUsers = []
      this.currentUsers = []
    },
    queryUser(id) {
      api.users
        .getUserInfo(id, {params: this.giveParams})
        .then(res => {
          if (res.data.code == 200) {
            this.givePrizes = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    giveUser(e) {
      console.log(e)
      console.log(e.blind_box.id)
      this.giveGoodsId = e.id
      this.givePrizeId = e.blind_box.id
      this.giveShow = true
      this.selectUsers = []
      this.currentUsers = []
      this.queryUser(e.blind_box.id)
      // this.blind_box_id = e.blind_box.id
    },
    handleSelectionChange(val) {
      this.currentUsers = val
    },
    log(row) {
      this.logSearchParams.blind_box_id = row.id;
      this.logTitle = row.name;
      this.status = "log";
      this.getLog();
    },
    getLog() {
      this.logTableLoading = true;
      api.blindBoxOrderPrizeLogs
        .index({params: this.logSearchParams})
        .then(res => {
          if (res.data.code == 200) {
            this.logTableLoading = false;
            this.logData = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    editPrizeSubmit() {
      if (this.editPrizeParams.probability <= 0) {
        this.$message.error("概率不能小于0");
        return;
      }
      this.load();
      api.blindBoxPrizes
        .edit(this.editPrizeParams.id, this.editPrizeParams)
        .then(res => {
          this.unload();
          if (res.data.code == 200) {
            this.$message.success(res.data.msg);
            this.editPrizeStatus = false;
            this.getPrize();
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    editPrize(id) {
      this.load();
      api.blindBoxPrizes
        .show(id)
        .then(res => {
          this.unload();
          if (res.data.code == 200) {
            this.editPrizeParams = res.data.data;
            this.editPrizeStatus = true;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 最终确定选择赏品
    addPrizeSubmit() {
      if (this.submitPrizeData.length == 0) {
        this.$message.error("请选择赏品");
        return;
      }

      for (var i = 0; i < this.submitPrizeData.length; i++) {
        if (!this.submitPrizeData[i].recovery_price) {
          this.$message.error("请输入兑换价");
          return false;
        }
        if (!this.submitPrizeData[i].num) {
          this.$message.error("请输入数量");
          return false;
        }
        if (this.submitPrizeData[i].num <= 0) {
          this.$message.error("数量不能小于0");
          return false;
        }
      }

      api.fusionPrizes
        .store({
          blindBoxId: this.prizeSearchParams.blindBoxId,
          prize: this.submitPrizeData
        })
        .then(res => {
          if (res.data.code == 200) {
            this.prizeStatus = false;
            this.submitPrizeData = [];
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    selectPrizeSubmit() {
      this.submitPrizeData = this.addPrizeData;
      this.addPrizeStatus = false;
      this.addPrizeData = [];
    },
    changePrize(e) {
      this.addPrizeData = e;
    },
    getSelectPrize() {
      this.addPrizeData = [];
      this.addPrizeLoading = true;
      api.common
        .getFPrize({params: this.selectPrizeParams})
        .then(res => {
          if (res.data.code == 200) {
            this.addPrizeLoading = false;
            this.selectPrizeData = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    selectPrize() {
      this.addPrizeStatus = true;
      this.getSelectPrize();
    },
    // 显示第一个选择赏品框
    addPrize() {
      this.prizeStatus = true;
    },
    prize() {
      this.prizeStatus = true;

      // this.status = "prize";
      // this.prizeSearchParams.blindBoxId = id;
      // this.getPrize();
    },
    getPrize() {
      this.prizeTableLoading = true;
      api.blindBoxPrizes
        .index({params: this.prizeSearchParams})
        .then(res => {
          this.prizeTableLoading = false;
          if (res.data.code == 200) {
            this.prizeData = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    changeStatus(e) {
      this.load();
      api.fusionPrizes
        .status(e.id, {status: e.status})
        .then(res => {
          this.unload();
          if (res.data.code === 200) {
            this.$message.success("保存成功");
            this.init();
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 组件图片上传成功取消遮罩重新请求数据
    uploadFileSuccess(res) {
      this.unload();
      this.getImages();
      this.$message.success(res.msg);
    },
    // 查看图片
    getImages() {
      this.cardStatus = true;
      this.imageLoading = true;
      api.images
        .index({params: this.imageParams})
        .then(res => {
          this.imageLoading = false;
          if (res.data.code == 200) {
            this.imageData = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 组件确定选择图片
    choiceImageConfirm(choiceImages) {
      if (this.scene == 1) {
        this.editParams.goods_images = this.editParams.goods_images.concat(
          choiceImages
        );
      } else if (this.scene == 2) {
        this.editParams.image = choiceImages[0];
      } else if (this.scene == 3) {
        this.extra.row.image = choiceImages[0];
      } else if (this.scene == 4) {
        var html = "";
        choiceImages.map(item => {
          html += `<div><img src="${item}" /></div>`;
        });
        this.setHtml(html);
        console.log("html:", html);
      }
    },
    // 改变图片组件每页条数时
    changeImageSize(limit) {
      this.imageParams.limit = limit;
      this.getImages();
    },
    // 改变图片组件当前页码时
    changeImagePage(page) {
      this.imageParams.page = page;
      this.getImages();
    },
    // 改变图片组件每页条数时
    changePrizeSize(limit) {
      this.prizeSearchParams.limit = limit;
      this.getPrize();
    },

    // 改变图片组件当前页码时
    changePrizePage(page) {
      this.prizeSearchParams.page = page;
      this.getPrize();
    },
    // changeSelectPrizeSize

    changeSelectPrizeSize(limit) {
      this.selectPrizeParams.limit = limit;
      this.getSelectPrize();
    },
    changeSelectPrizePage(page) {
      this.selectPrizeParams.page = page;
      this.getSelectPrize();
    },

    // 改变图片组件每页条数时
    changeLogSize(limit) {
      this.logSearchParams.limit = limit;
      this.getLog();
    },
    // 改变图片组件当前页码时
    changeLogPage(page) {
      this.logSearchParams.page = page;
      this.getLog();
    },
    // 打开组件图片
    openImage(scene, multiple, extra) {
      this.multiple = multiple; // 单选还是多选
      this.scene = scene;
      this.extra = extra; // 额外数据
      this.cardStatus = true;
      this.getImages();
    },
    uploadImageBefore() {
      this.load();
    },
    closeImage() {
      this.cardStatus = false;
    },
    // 重置图片搜索参数
    initImage(type) {
      this.imageParams.format = type;
      this.imageParams.page = 1;
    },
    // 选择类型筛选图片
    changeImageFormat(type) {
      this.initImage(type);
      this.getImages();
    },
    // 查看大图
    bigImage(url) {
      this.$alert("图片", {
        message: "<img  src=" + url + " style='height:200px;width:200px'>",
        dangerouslyUseHTMLString: true
      });
    },
    back() {
      this.status = "index";
      this.logSearchParams.page = 1;
      this.prizeSearchParams.page = 1;
    },
    // 获取所有等级
    getLevel() {
      api.common
        .goodsLevels()
        .then(res => {
          if (res.data.code === 200) {
            this.levelData = res.data.data;
          }
        })
        .catch(error => {
        });
    },

    // 加载中
    load() {
      this.loading = this.$loading({
        lock: true,
        text: "数据加载中",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
    },

    // 取消加载
    unload() {
      this.loading.close();
    },
    // 获取所有数据
    getData() {
      this.table_loading = true;
      api.fusionPrizes
        .index({params: this.searchParams})
        .then(res => {
          if (res.data.code === 200) {
            this.table_loading = false;
            this.data = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 重置搜索参数重新搜索
    reset() {
      this.searchParams.name = "";
      this.searchParams.startTime = "";
      this.searchParams.endTime = "";
      this.init();
    },
    submit(formName, type) {
      this.$refs[formName].validate((valid, error) => {
        if (valid) {
          // 添加

          var flag = true;
          for (var i = 0; i < this.editParams.probability.length; i++) {
            if (!this.editParams.probability[i].value) {
              flag = false;
              break;
            }
            if (this.editParams.probability[i].value < 0) {
              this.$message.error("概率不能小于0");
              return;
            }
          }
          if (!flag) {
            this.$message.error("请填写概率");
            return;
          }
          this.load();
          if (type === 1) {
            api.blindBox
              .store(this.editParams)
              .then(res => {
                this.unload();
                if (res.data.code === 200) {
                  this.init();
                }
              })
              .catch(error => {
                console.log(error);
              });
          } else if (type === 2) {
            // 编辑
            api.blindBox
              .edit(this.editParams.id, this.editParams)
              .then(res => {
                this.unload();
                if (res.data.code === 200) {
                  this.init();
                }
              })
              .catch(error => {
                console.log(error);
              });
          }
        } else {
          this.$message.error(Object.values(error)[0][0].message);
          return false;
        }
      });
    },
    del(id, index) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal: false,
        type: "warning"
      })
        .then(() => {
          this.load();
          api.towerTreasureBoxPrizes
            .del(id)
            .then(res => {
              this.unload();
              if (res.data.code === 200) {
                this.$message({
                  type: "success",
                  message: "删除成功!"
                });
                this.data.data.splice(index, 1);
                this.data.total--;
              }
            })
            .catch(error => {
              console.log(error);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    delPrize(id, index) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal: false,
        type: "warning"
      })
        .then(() => {
          this.load();
          api.blindBoxPrizes
            .del(id)
            .then(res => {
              this.unload();
              if (res.data.code === 200) {
                this.$message({
                  type: "success",
                  message: "删除成功!"
                });
                this.prizeData.data.splice(index, 1);
                this.prizeData.total--;
              }
            })
            .catch(error => {
              console.log(error);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    delLog(id) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal: false,
        type: "warning"
      })
        .then(() => {
          this.load();
          api.blindBoxOrderPrizeLogs
            .del(id)
            .then(res => {
              this.unload();
              if (res.data.code === 200) {
                this.$message({
                  type: "success",
                  message: "删除成功!"
                });
                this.logData.data.splice(index, 1);
                this.logData.total--;
              }
            })
            .catch(error => {
              console.log(error);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    // 初始化
    init() {
      this.editParams = {
        name: "",
        image: "",
        sort: "",
        price: "",
        three_price: "",
        five_price: "",
        cat_id: "",
        probability: [
          {name: "尊贵", level_id: 1},
          {name: "稀有", level_id: 2},
          {name: "史诗", level_id: 3},
          {name: "传说", level_id: 4}
        ]
      };
      this.back();
      this.getData();
    },
    //改变兑换价格
    updateNum(row) {
      this.$nextTick(() => {
        this.load();
        api.fusionPrizes
          .updateNum(row)
          .then(res => {
            if (res.data.code === 200) {
              this.unload();
              this.$message({
                type: "success",
                message: "修改成功!"
              });
              this.status = "edit";
              this.editParams = res.data.data;
            }
          })
          .catch(error => {
            console.log(error);
          });
      });
    },
    //改变兑换价格
    updateRecoveryPrice(row) {
      this.$nextTick(() => {
        this.load();
        api.fusionPrizes
          .updateRecoveryPrice(row)
          .then(res => {
            if (res.data.code === 200) {
              this.unload();
              this.$message({
                type: "success",
                message: "修改成功!"
              });
              this.status = "edit";
              this.editParams = res.data.data;
            }
          })
          .catch(error => {
            console.log(error);
          });
      });
    },
    // 改变每页条数时
    usersChangeSize(limit) {
      this.giveParams.limit = limit;
      this.queryUser();
    },
    // 改变当前页码时
    usersChangePage(page) {
      this.giveParams.page = page;
      this.queryUser();
      this.selectUsers.push(...this.currentUsers)
      this.currentUsers = []
    },
    // 改变每页条数时
    changeSize(limit) {
      this.searchParams.limit = limit;
      this.getData();
    },
    // 改变当前页码时
    changePage(page) {
      this.searchParams.page = page;
      this.getData();
    },
    add() {
      this.status = "add";
    },
    // 添加页面
    detail(id) {
      this.load();
      api.blindBox
        .show(id)
        .then(res => {
          if (res.data.code === 200) {
            this.unload();
            this.status = "edit";
            this.editParams = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    }
  }
};
</script>

<style scoped lang="less">
.demo-table-expand {
  font-size: 0;
}

.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
